package com.atguigu.gmall.item.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.SkuDetailService;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("获取sku详情")
@RequestMapping("/api/inner/rpc/product")
@RestController
public class SkuDetailRpcController {

    @Autowired
    SkuDetailService skuDetailService;

    @ApiOperation("获取商品详情数据")
    @GetMapping("/sku/detail/{skuId}")
    public Result<SkuDetailVo> getSkuDetails(@PathVariable("skuId") Long skuId){
        //todo 获取商品详情数据
        //引入切面：如果缓存中有数据，方法都不用调
        SkuDetailVo skuDetails = skuDetailService.getSkuDetailData(skuId);

        //增加热度分
        skuDetailService.incrHotScore(skuId);

        return Result.ok(skuDetails);
    }
}
